package com.feonix.common.view.grid;

import java.util.ArrayList;
import java.util.List;

import org.springframework.ui.ModelMap;

import com.feonix.common.util.StringUtil;

public class GridRow {

	protected List<GridCell> gridCells = new ArrayList<GridCell>();
	private Integer index;
	private GridView gridView;
	private ModelMap modelMap;

	public GridCell addCell(String field, Object value) {
		return addCell(field, value, "");
	}

	public GridCell addCell(String field, Object value, boolean escape) {
		return addCell(field, value, "", escape);
	}

	public GridCell addCell(String field, Object value, String onClick) {
		GridCell gridCell = new GridCell(field, StringUtil.getString(value), onClick);
		this.gridCells.add(gridCell);
		return gridCell;
	}

	public GridCell addCell(String field, Object value, String onClick, boolean escape) {
		GridCell gridCell = new GridCell(field, StringUtil.getString(value), onClick, escape);
		this.gridCells.add(gridCell);
		return gridCell;
	}

	public List<GridCell> getGridCells() {
		return this.gridCells;
	}

	public Integer getIndex() {
		return this.index;
	}

	public GridView getGridView() {
		return this.gridView;
	}

	public void setIndex(Integer index) {
		this.index = index;
	}

	public void setGridView(GridView gridView) {
		this.gridView = gridView;
	}

	public void setModelMap(ModelMap modelMap) {
		this.modelMap = modelMap;
	}

	/**
	 * 获得gridview中的model值
	 * 
	 * @param key
	 * @return
	 */
	public <T> T getGridObject(String key) {
		T t = null;
		if (this.modelMap != null) {
			t = (T) this.modelMap.get(key);
		}
		return t;
	}

}
